package b1.scenes.run
{
	import b1.controls.tab.*;
	import b1.net.*;
	import b1.players.*;
	import b1.scenes.crime.*;
	import b1.scenes.detect.*;
	import b1.scenes.home.*;
	import b1.scenes.home.wanted.*;
	import b1.utils.*;
	
	
	import flash.display.Sprite;
	import flash.text.*;
	import flash.filters.*;
	import flash.media.Sound;

	public class RunAwayDialog extends TabController
	{
		private static var instance:RunAwayDialog;
		public var runawayAnimal:AnimalInfo;
		
		public function RunAwayDialog()
		{
			var TabControllerBackground:Class = ResourceHelper.getInstance().getClassByName("TabControllerBackground");
			var TabTitleBackground:Class = ResourceHelper.getInstance().getClassByName("TabTitleBackground");
			var CloseButton:Class = ResourceHelper.getInstance().getClassByName("CloseButton1");
			super(TabControllerBackground, CloseButton);
			var tab:Tab = new Tab("邻居", 4, 2, 5, 3);
			this.addTab(TabTitleBackground, tab);
			tab = new Tab("好友", 4, 2, 5, 3);
			this.addTab(TabTitleBackground, tab);
			//标题
			var titleText:TextField = new TextField();
			titleText.selectable = false;
        	titleText.autoSize = TextFieldAutoSize.CENTER;
        	titleText.width = 45;
        	titleText.wordWrap = true;
        	titleText.filters = [BFont.greenFontGlowFilter];
			titleText.defaultTextFormat = new TextFormat("微软雅黑", 20, 0x000000, true, true);
			titleText.text = "请 选 择 跑 路 的 目 的 地 ？ ";
			titleText.x = 80;
			titleText.y = 60;
			addChild(titleText);
			
		}
		
		public function refresh():void
		{
			for (var i:int = 0; i < tabs.length; i++)
			{
				this.tabs[i].removeAll();
			}
			var players:Object = PlayerInfoHelper.getInstance().players;
			for (var playerId:String in players)
			{
				var player:PlayerInfo = players[playerId];
				//只能跑路到非虚拟玩家中
				if (player.id > 0 && player.type > 0 && player.name != "")
				{
					var runAwayItem:RunAwayItem = new RunAwayItem(player);
					(this.tabs[player.type - 1] as Tab).addItem(runAwayItem, 125, 125);
				}
			}
		}

		public static function getInstance():RunAwayDialog
		{
			if (!instance)
				instance = new RunAwayDialog();
			return instance;
		}
		
		public function open(runawayAnimal:AnimalInfo, parentScene:Sprite):void
		{
			this.runawayAnimal = runawayAnimal;
			refresh();
			if (!parentScene.contains(this))
			{
				this.x = (BFont.stageWidth - this.width) / 2;
				this.y = 40;
				parentScene.addChild(this);
				//播放音效
				var SoundButton1:Class = ResourceHelper.getInstance().getClassByName("SoundButton1");
				var sound:Sound = new SoundButton1();
				sound.play(); 
			}
			WantedTab.getInstance().close();
			Store.getInstance().close();
			DetectDiaglog.getInstance().close();
			CrimeDialog.getInstance().close();
			BottomNavigator.getInstance().hide();
		}
		
		public function close():void
		{
			if (this.parent != null)
				this.parent.removeChild(this);
		}
		
	}
}